package com.cloudmusic.controller;

import javax.servlet.http.HttpSession;

import com.cloudmusic.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.cloudmusic.constant.Const;
import com.cloudmusic.service.SelectService;

@Controller
@RequestMapping("music/select")
public class SelectController {

	@Autowired
	SelectService selectService;

	//登录前查找所有歌曲
	@RequestMapping("selectallmusic")
	@ResponseBody
	public JSONObject selectAll() {
		JSONObject json = selectService.selectAll();
		return json;
	}

    //登录后查找所有歌曲
    @RequestMapping("selectloginallmusic")
    @ResponseBody
    public JSONObject selectloginAll(HttpSession session) {
        String userId = ((User)session.getAttribute(Const.SESSION_KEY)).getUid();
        JSONObject json = selectService.selectLoginAll(userId);
        return json;
    }
	
	@RequestMapping("selectlikemusic")
	@ResponseBody
	public JSONObject selectLike(HttpSession session) {
		String userId = ((User)session.getAttribute(Const.SESSION_KEY)).getUid();
		JSONObject json = selectService.selectLike(userId);
		return json;
	}


	@RequestMapping("selectcollectionmusic")
	@ResponseBody
	public JSONObject selectCollection(HttpSession session) {
		String userId = ((User)session.getAttribute(Const.SESSION_KEY)).getUid();
		JSONObject json = selectService.selectCollection(userId);
		return json;
	}

	@RequestMapping("selecthistorymusic")
	@ResponseBody
	public JSONObject selectHistory(HttpSession session) {
		String historyLid = (String)session.getAttribute(Const.HISTORYLIST_ID);
        String userId = ((User)session.getAttribute(Const.SESSION_KEY)).getUid();
		JSONObject json = selectService.selectHistory(historyLid,userId);
		return json;
	}
	
	
}
